package com.project.service.imp;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.StudentBean;
import com.project.mapper.IStudentMapper;
import com.project.service.IStudentService;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
@Service
@Transactional
public class StudentServiceImp implements IStudentService {
    @Autowired
    private IStudentMapper stuMapper;
    @Override
    public ArrayList<StudentBean> showAllStudents() {
        return stuMapper.showAllStudents();
    }

    @Override
    public void studentIn(StudentBean newStudent) {
        stuMapper.insert(newStudent);
    }

    @Override
    public void studentOut(Integer stuId) {
        stuMapper.deleteById(stuId);
    }



    @Override
    public void studentChange(Integer stuId, Integer newRoomId) {
        StudentBean studentBean = stuMapper.selectById(stuId);
        studentBean.setRoomId(newRoomId);
        stuMapper.updateById(studentBean);
    }

    @Override
    public StudentBean studentById(Integer stuId) {
        return stuMapper.studentById(stuId);
    }

    @Override
    public IPage<StudentBean> cutPageByCondition(Integer pageNum, String stuName, String className, String roomAddress) {
        return  stuMapper.cutPageByCondition(new Page(pageNum,2),stuName,className,roomAddress);
    }


}
